import fs = require("fs");
import path = require('path');

export class Config {
    private static instance: Config;
    private config: any;

    constructor() {
        if (process.env.DEBUG_CONFIG == 'true') {
            this.config = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'debug_config.json'), "utf-8"));
        }
        else {
            this.config = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'scoreconfig.json'), "utf-8"));
        }
    }

    get appId(): string {
        return this.config.appId;
    }

    get serverUrl(): string {
        return this.config.serverUrl;
    }

    get mchId(): string {
        return this.config.mchId;
    }

    get privateKey(): string {
        return this.config.privateKey;
    }


    get serialNo(): string {
        return this.config.serialNo;
    }

    get serviceId(): string {
        return this.config.serviceId;
    }

    get platSerialNo(): string {
        return this.config.platSerialNo;
    }

    get platPublicKey(): string {
        return this.config.platPublicKey;
    }

    get openId(): string {
        return this.config.openId;
    }

    get pemissionCallbackUrl(): string {
        return this.config.pemissionCallbackUrl;
    }

    get payCallbackUrl(): string {
        return this.config.payCallbackUrl;
    }
    public static getInstance(): Config {
        if (!Config.instance) {
            Config.instance = new Config();
        }
        return Config.instance;
    }
}
